    if(window.XMLHttpRequest) {
        var XMLHttp = new XMLHttpRequest();
    } else {
        var MSXML = ['MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
        for(var n = 0; n < MSXML.length; n ++) {
            try {
                var XMLHttp = new ActiveXObject(MSXML[n]);        
                break;
            } catch(e) {
            }
        }
    }
    window.onload = function() {
        var answerHTML='';
    }
    function temp() {
        document.getElementById("poll_count").onchange = function () {
            if(document.getElementById("poll_customcount").value!='') {
            } else {
            for(var i =0,len = this.options.length;i<len;i++) {
                if(this.options[i].selected) {

                    a(this.options[i].value);
                }
            }
            }
        }
        document.getElementById("poll_customcount_return").onclick = function () {
            if(1) {
                var poll_count = document.getElementById("poll_count");
                for(var i =0,len = poll_count.options.length;i<len;i++) {
                    if(poll_count.options[i].selected) {
                        a(poll_count.options[i].value);
                    }
                }
                document.getElementById("poll_customcount").value = '';
            }
        }
        document.getElementById("poll_customcount_submit").onclick = function () {
            answerHTML  = document.getElementById("answerarea").innerHTML;
            var count = parseInt(document.getElementById("poll_customcount").value);
            if(count<=30 && count>=3) {
                a(count);
            } else {
                alert("please check your count,it must between 3 to 30");
            }
        }
        var dels = document.getElementsByName("delanswer");
        for(var i=0;i<dels.length;i++) {
            dels[i].onclick = function () {
                delLastAnswer(this);
            }
        }
    }
	function voteContent(pid) {
		var cid=[];
		oContents = document.getElementsByName("poll_content");
		for(var i=0,len = oContents.length;i<len;i++) {
			if(oContents[i].checked) {
				cid.push(oContents[i].value);
			}
		}
		cid = cid.join(",");
		XMLHttp.open("POST","example.php",true);
        XMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        XMLHttp.send("pid="+pid+"&cid="+cid+"&act=voteContent");
		XMLHttp.onreadystatechange = function() {
			if(XMLHttp.readyState==4) {
				var oDiv = document.createElement("div");
				document.body.appendChild(oDiv);
				oDiv.innerHTML = XMLHttp.responseText;
			}
		}
	}
    function createAjaxArea() {
        var oAjaxDiv = document.getElementById("ajaxarea");
        if(oAjaxDiv!=null) {
            return true;
        } else {
			var oDiv = document.createElement("div");
    		document.body.appendChild(oDiv);
            oDiv.setAttribute("id","ajaxarea");
            oDiv.setAttribute("style","margin:20px;border:1px solid #ddd;padding:20px;");
            return true;
        }
    }
    function editPoll(pid) {
        XMLHttp.open("POST","example.php",true);
        XMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        XMLHttp.send("pid="+pid+"&act=editPoll");
        XMLHttp.onreadystatechange = function() {
			if(XMLHttp.readyState==4) {
                if(createAjaxArea()) {
        			var oDiv = document.createElement("div");
	    			document.getElementById("ajaxarea").appendChild(oDiv);
		    		oDiv.innerHTML = XMLHttp.responseText;
                    window.setTimeout("temp()",1000);
                }
			}
		}
    }

    function deletePoll(pid) {
        XMLHttp.open("POST","example.php",true);
        XMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        XMLHttp.send("pid="+pid+"&act=deletePoll");
		XMLHttp.onreadystatechange = function() {
			if(XMLHttp.readyState==4) {
				var oDiv = document.createElement("div");
				document.body.appendChild(oDiv);
				oDiv.innerHTML = XMLHttp.responseText;
			}
		}

    }
    function newPoll() {
        XMLHttp.open("POST","example.php",true);
        XMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        XMLHttp.send("act=newPoll");
        XMLHttp.onreadystatechange = function() {
			if(XMLHttp.readyState==4) {
				var oDiv = document.createElement("div");
				document.body.appendChild(oDiv);
				oDiv.innerHTML = XMLHttp.responseText;
                window.setTimeout("temp()",200);
			}
		}
    }
	function showContentDetail(pid) {
		XMLHttp.open("POST","example.php",true);
        XMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        XMLHttp.send("pid="+pid+"&act=contentDetail");
        XMLHttp.onreadystatechange = function() {
			if(XMLHttp.readyState==4) {
                if(createAjaxArea()) {
				var oDiv = document.createElement("div");
				oDiv.setAttribute("style","border:1px solid #cdc;");
				document.getElementById("ajaxarea").innerHTML =XMLHttp.responseText;
//				oDiv.innerHTML = XMLHttp.responseText;
                }
			}
		}
	}
    function delLastAnswer(obj) {
        obj.parentNode.parentNode.removeChild(obj.parentNode);
        return;
        var dels = document.getElementsByName("delanswer");
        var answer = document.getElementById("answerarea");
        var poll_count = document.getElementById("poll_count");
        if(dels.length==3) {
            alert("the answers cannot less than 3");
        } else {
            for(var i=0,len = poll_count.options.length;i<len;i++) {
                if(poll_count.options[i].value==dels.length-1) {
                    poll_count.options[i].selected="selected";
                }
            }
            answer.removeChild(dels[dels.length-1].parentNode);
        }
    }
    function a(num) {
        var tmpdata = getContents();
        document.getElementById("answerarea").innerHTML = setContents(num,tmpdata);
        temp();
    }
    function selectCount(num) {
        var oCount = document.getElementById("poll_count");
        for(var i=0;i<oCount.length;i++) {
            if(oCount.options[i].value==num) {
                oCount.options[i].selected='selected';
            }
        }
    }
    function getContents() {
        var oContent = document.getElementsByName("poll_answer[]");
        var cid = document.getElementsByName("poll_cid[]");
        var back_Content = [];
        var back_cid = [];
        for(var i=0,len = oContent.length;i<len;i++) {
            if(oContent[i].value!='') {
                back_Content.push(oContent[i].value);
                back_cid.push(cid[i].value);
            }
        }
        return [back_Content,back_cid];
    }
    function setContents(num,contents) {
        var back_Contents = contents[0];
        var back_cid = contents[1];
        var html = '';
        for(var i=0,len=back_Contents.length;i<len;i++) {
            html += "<p>Answer "+(i+1)+":<input type='hidden' value='"+back_cid[i]+"' name='poll_cid[]' /><input type='text' value='"+back_Contents[i]+"' name='poll_answer[]' id='poll_answer_"+i+"' /><input type='button' value='-' name='delanswer' /></p>";
        }
        var j=1;
        for(var i=back_Contents.length;i<num;i++) {
            html += "<p>Answer "+(i+1)+":<input type='hidden' value='"+(parseInt(back_cid[back_cid.length-1])+j)+"' name='poll_cid[]' /><input type='text' value='' name='poll_answer[]' id='poll_answer_"+i+"' /><input type='button' value='-' name='delanswer' /></p>";
            j++;
        }
        return html;
    }
    function ResetAnswer(num) {
        var html = '';
        for(var i=0;i<num;i++) {
            html +="<p>Answer "+(i+1)+":<input type='text' value='' name='poll_answer[]' id='poll_answer_"+i+"' /><input type='button' value='-' name='delanswer' /></p>";
        }
        return html;
    }